package com.allen.study.application.api;

import com.allen.study.application.api.request.DepartmentCreateRequest;
import com.allen.study.application.api.request.DepartmentQueryRequest;
import com.allen.study.application.api.request.DepartmentUpdateRequest;
import com.allen.study.application.api.response.DepartmentQueryResponse;
import com.allen.study.application.api.response.DepartmentResponse;
import com.allen.study.application.service.DepartmentAppService;
import com.allen.study.common.base.ApiPageResponse;
import com.allen.study.common.base.ApiResponse;
import com.allen.study.common.base.Pagination;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * 部门信息表接口
 *
 * @author AllenSun
 * @since 2025-04-23 20:46
 */
@RequestMapping(value = "/4.2.0/department")
@RestController
@AllArgsConstructor
@Tag(name = "部门信息表接口", description = "部门信息表接口")
public class DepartmentApi {

    /**
     * 部门信息表应用服务
     */
    private final DepartmentAppService departmentAppService;

    /**
     * 创建部门信息表
     *
     * @param createRequest 部门信息表创建对象
     * @return 响应结果
     */
    @PostMapping
    @Operation(summary = "创建部门信息表", description = "创建部门信息表")
    public ApiResponse<Void> create(@RequestBody @Valid DepartmentCreateRequest createRequest) {
        return departmentAppService.create(createRequest);
    }

    /**
     * 根据主键删除部门信息表
     *
     * @param departmentId 部门信息表主键
     * @return 响应结果
     */
    @DeleteMapping(value = "/{department_id}")
    @Operation(summary = "根据主键删除部门信息表", description = "根据主键删除部门信息表")
    public ApiResponse<Void> deleteById(@PathVariable(name = "department_id") String departmentId) {
        return departmentAppService.deleteById(departmentId);
    }

    /**
     * 根据主键更新部门信息表
     *
     * @param departmentId 部门信息表主键
     * @param updateRequest 部门信息表更新对象
     * @return 响应结果
     */
    @PutMapping(value = "/{department_id}")
    @Operation(summary = "根据主键更新部门信息表", description = "根据主键更新部门信息表")
    public ApiResponse<Void> updateById(@PathVariable(name = "department_id") String departmentId,
            @RequestBody @Valid DepartmentUpdateRequest updateRequest) {
        return departmentAppService.updateById(departmentId, updateRequest);
    }

    /**
     * 根据主键查询部门信息表详情
     *
     * @param departmentId 部门信息表主键
     * @return 响应结果
     */
    @GetMapping(value = "/{department_id}")
    @Operation(summary = "根据主键查询部门信息表详情", description = "根据主键查询部门信息表详情")
    public ApiResponse<DepartmentResponse> queryById(@PathVariable(name = "department_id") String departmentId) {
        return departmentAppService.queryById(departmentId);
    }

    /**
     * 分页查询部门信息表
     *
     * @param pagination   分页
     * @param queryRequest 部门信息表查询对象
     * @return 响应结果
     */
    @GetMapping
    @Operation(summary = "分页查询部门信息表", description = "分页查询部门信息表")
    public ApiPageResponse<DepartmentQueryResponse> query(@Valid Pagination pagination, @Valid DepartmentQueryRequest queryRequest) {
        return departmentAppService.query(pagination, queryRequest);
    }
}
